package main

import (
	"fmt"
	"sync"
)

func add(count *int, wg *sync.WaitGroup, lock *sync.Mutex) {
	defer wg.Done()
	for i := 0; i < 10000; i++ {
		lock.Lock()
		*count = *count + 1
		lock.Unlock()
	}
}

func main() {
	var wg sync.WaitGroup
	lock := &sync.Mutex{}
	wg.Add(5)
	count := 0
	for i := 0; i < 5; i++ {
		go add(&count, &wg, lock)
	}
	wg.Wait()
	fmt.Println("执行后的结果为：", count)

}
